package com.danicsoft.daide.command;

import com.danicsoft.daide.token.TokenMap.Commands;
import com.danicsoft.daide.token.TokenGroup;

/**
 * Implements the LOD command. From Eric Wald's <a
 * href="http://pydip.brainshell.org/docs/syntax.html">protocol specification</a>,
 * v0.14:
 * 
 * @author Daniel Yule (daniel.yule@gmail.com)
 * @version 1.0
 */
public class LoadCommand extends Command {

	/**
	 * The name of the game we are loading
	 */
	private String gameName;

	/**
	 * Creates a new instance of LoadCommand from the tokens given
	 * 
	 * @param tokens
	 *        A <code>TokenGroup</code> with a single sub
	 *        <code>TokenGroup</code> containing a text token
	 * @throws ParseException
	 *         If there was a problem parsing the <code>TokenGroup</code<
	 */
	public LoadCommand(TokenGroup tokens) throws ParseException {
		super(tokens);
	}

	/**
	 * Constructs a new LoadCommand from the game name given.
	 * 
	 * @param gameName
	 *        The name of the game we want to load
	 */
	public LoadCommand(String gameName) {
		super();
		this.gameName = gameName;
	}

	@Override
	public byte getType() {
		return Commands.LOD;
	}

	@Override
	public String toString() {
		return "Load game: " + gameName;
	}

	public void doIO(TokenIO tokenIO, TokenGroup tokens) throws ParseException {
		gameName = tokenIO.doText(tokenIO.subGroup(tokens), gameName);

	}
	
	/**
	 * Gets the name of the game we are saving.
	 * 
	 * @return The name of the game we are saving.
	 */
	public String getGameName() {
		return gameName;
	}

}
